{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Defanging an IP Address"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: defangIPaddr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #IP 地址无效化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个有效的 <a href=\"https://baike.baidu.com/item/IPv4\" target=\"_blank\">IPv4</a> 地址&nbsp;<code>address</code>，返回这个 IP 地址的无效化版本。</p>\n",
    "\n",
    "<p>所谓无效化&nbsp;IP 地址，其实就是用&nbsp;<code>&quot;[.]&quot;</code>&nbsp;代替了每个 <code>&quot;.&quot;</code>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>address = &quot;1.1.1.1&quot;\n",
    "<strong>输出：</strong>&quot;1[.]1[.]1[.]1&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>address = &quot;255.100.50.0&quot;\n",
    "<strong>输出：</strong>&quot;255[.]100[.]50[.]0&quot;\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li>给出的&nbsp;<code>address</code>&nbsp;是一个有效的 IPv4 地址</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [defanging-an-ip-address](https://leetcode.cn/problems/defanging-an-ip-address/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [defanging-an-ip-address](https://leetcode.cn/problems/defanging-an-ip-address/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"1.1.1.1\"', '\"255.100.50.0\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        res = ''\n",
    "        for i in address:\n",
    "            if i == '.':\n",
    "                res += '[.]'\n",
    "            else:\n",
    "                res += i\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        #--------------------------#\n",
    "        # 两步走\n",
    "        #--------------------------#\n",
    "        l = len(address)\n",
    "        nums = l//2 + 1\n",
    "        # 需要添加6个括号\n",
    "        word = ['' for i in range(l + 6)]\n",
    "        keep = []\n",
    "        fast = 0 #快指针指向address，慢指针指向生成字符\n",
    "        for fast in range(l):\n",
    "         if address[fast] == '.':\n",
    "           keep.append(fast) #记录下点的坐标 [)\n",
    "        #处理前置\n",
    "        sub = address[0:keep[0]]\n",
    "        word.append(sub)\n",
    "        word.append('[.]')\n",
    "        for i in range(1,len(keep)):\n",
    "            pre = keep[i-1] + 1\n",
    "            #i 表示当前的\n",
    "            sub = address[pre:keep[i]]\n",
    "            word.append(sub)\n",
    "            word.append('[.]')\n",
    "        #处理后置\n",
    "        sub = address[keep[i]+1:l]\n",
    "        word.append(sub)\n",
    "        return ''.join(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        res = ''\n",
    "        for i in address:\n",
    "            if i == '.':\n",
    "                res += '[.]'\n",
    "            else:\n",
    "                res += i\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        result = ''\n",
    "        for c in address:\n",
    "            if c == '.':\n",
    "                result += '[.]'\n",
    "            else:\n",
    "                result += c\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        ret = []\n",
    "        for ch in address:\n",
    "            if ch == '.':\n",
    "                ret.append(\"[\")\n",
    "                ret.append(ch)\n",
    "                ret.append(\"]\")\n",
    "            else:\n",
    "                ret.append(ch)\n",
    "        return ''.join(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\" , \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return \"[.]\".join(address.split('.'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        res = \"\"\n",
    "        for add in address:\n",
    "            if add == \".\":\n",
    "                res += \"[.]\"\n",
    "            else :\n",
    "                res += add\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        adds=address.split('.')\n",
    "        n=len(adds)\n",
    "        res=''\n",
    "        for i in range(n-1):\n",
    "            res+=adds[i]+'[.]'\n",
    "        res+=adds[n-1]\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        a = address.split('.')\n",
    "        b = '[.]'.join(a)\n",
    "        return b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        address = address.replace('.', '[.]')\n",
    "        return address"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        ret = \"\"\n",
    "        for i in address:\n",
    "            if i == \".\":\n",
    "                ret +=\"[.]\"\n",
    "            else:\n",
    "                ret += i\n",
    "        return ret \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        s=\"\"\n",
    "        for c in address:\n",
    "            if c==\".\":\n",
    "                s+=\"[.]\"\n",
    "            else:\n",
    "                s+=c\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        # return address.replace(\".\",\"[.]\")\n",
    "\n",
    "        res = \"\"\n",
    "        for i in address:\n",
    "            if i == \".\":\n",
    "                res += \"[.]\"\n",
    "                continue\n",
    "            res += i\n",
    "        return res            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        tempadr = address.split('.')\n",
    "        newadr = '[.]'.join(tempadr)\n",
    "        return newadr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        new = address.replace(\".\",\"[.]\")\n",
    "        return new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "from collections import Counter, defaultdict\n",
    "from itertools import product\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class ListNode:\n",
    "    def __init__(self, val=0, next=None):\n",
    "        self.val = val\n",
    "        self.next = next\n",
    "\n",
    "\n",
    "class TreeNode:\n",
    "    def __init__(self, val=0, left=None, right=None):\n",
    "        self.val = val\n",
    "        self.left = left\n",
    "        self.right = right\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        s=\"\"\n",
    "        # address=address.replace('.','[.]')\n",
    "        print(address)\n",
    "        for c in address:\n",
    "            if c!=\".\":\n",
    "                s+=c\n",
    "            else:\n",
    "                s+='[.]'\n",
    "        print(s)\n",
    "        return s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return '[.]'.join(address.split('.'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        res = address.replace(\".\", \"[.]\")\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        ans = address.replace('.', '[.]')\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        ans = \"\"\n",
    "        for i in range(len(address)):\n",
    "            if address[i] == '.':\n",
    "                ans += \"[.]\"\n",
    "            else:\n",
    "                ans += address[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return  address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        address = address.split('.')\n",
    "        return '[.]'.join(address)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        f = \"\"\n",
    "        for i in address:\n",
    "            if i != \".\":\n",
    "                f += i\n",
    "            else:\n",
    "                f += \"[.]\"\n",
    "        return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\" , \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, a: str) -> str:\n",
    "        rs=\"\"\n",
    "        for i in a:\n",
    "            if i==\".\":\n",
    "                rs+=\"[.]\"\n",
    "            else:\n",
    "                rs+=i\n",
    "        return rs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        new_address=[]\n",
    "        for i in range(len(address)):\n",
    "            if address[i]==\".\":\n",
    "                new_address.append(\"[\")\n",
    "                new_address.append(\".\")\n",
    "                new_address.append(\"]\")\n",
    "            else:\n",
    "                new_address.append(address[i])\n",
    "        return \"\".join(new_address)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        n=address.split('.')\n",
    "        s=''\n",
    "        for k in range(len(n)-1):\n",
    "            s+=n[k]+'[.]'\n",
    "        s+=n[len(n)-1]\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.','[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\", \"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        new = address.replace('.', '[.]')\n",
    "        return new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace('.', '[.]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        return address.replace(\".\",\"[.]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        lst=address.split('.')\n",
    "        return ('[.]'.join(lst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def defangIPaddr(self, address: str) -> str:\n",
    "        res = re.sub(r'\\.', '[.]', address)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def defangIPaddr(self, address: str) -> str:\r\n",
    "        return address.replace('.','[.]')"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
